package com.huahua.api.enums;

import lombok.AllArgsConstructor;
import lombok.Getter;

/**
 * 表格文件格式枚举
 */
@Getter
@AllArgsConstructor
public enum TableFileFormatEnum {

    EXCEL("excel", "Excel格式(.xlsx/.xls)"),
    CSV("csv", "CSV格式(.csv)");

    private final String code;
    private final String description;

    /**
     * 根据文件扩展名获取格式
     */
    public static TableFileFormatEnum getByExtension(String extension) {
        if (extension == null) {
            return null;
        }
        String ext = extension.toLowerCase().replace(".", "");
        switch (ext) {
            case "xlsx":
            case "xls":
                return EXCEL;
            case "csv":
                return CSV;
            default:
                return null;
        }
    }
}
